<?php

namespace app\common\model;

class PropagandaEducationSatisfaction extends BaseModel
{
    /**
     * 获取条件数据
     *
     * @param array $where
     * @param string $field
     * @param string $sortField
     * @param string $sort
     * @return array
     */
    public function getDatas(array $where=[], string $field="*", string $sortField="created_at", string $sort="desc"): array
    {
        return $this->where($where)->field($field)->order($sortField, $sort)->select()->toArray();
    }

    /**
     * 添加数据
     * @param array $data
     * @return string
     */
    public function addData(array $data): string
    {
        //添加时销毁自带的主键id
        unset($data['id']);
        return $this->save($data);
    }

    /**
     * 更新数据
     * @param string $id
     * @param array $data
     * @return bool
     */
    public function saveData(string $id, array $data): bool
    {
        $model = self::find($id);
        return $model->save($data);
    }

    /**
     * 删除
     * @param string $id
     * @return bool
     */
    public function delData(string $id): bool
    {
        return self::destroy($id);
    }
}